import request from '@/utils/request'

// 获取机器人列表（分页）
export const getRobotsPage = (pageNum = 1, pageSize = 10) =>
  request.get('/robots/page', {
    params: { pageNum, pageSize }
  })

// 创建机器人
export const createRobot = (data) => request.post('/robots', data)

// 批量获取机器人详情
export const getRobotsByIds = (robotIds) =>
  request.get('/robots/batch', {
    params: { ids: robotIds }
  })
// 获取机器人详情
export const getRobotDetail = (id) => request.get(`/robots/${id}/status`)
// 获取机器人正在处理的警情id
export const getRobotAlertId = (id) => request.get(`/robots/${id}/alerts`)
// 获取低电量机器人列表
export const getLowBatteryRobots = () => request.get('/robots/low-battery')

// 获取机器人概览数据
export const getRobotOverview = () => request.get('/robots/overview')

// 获取在线机器人数量
export const getRobotCount = (status) =>
  request.get('/robots/count', {
    params: { status }
  })

export const getRobotBatteryThresholdCount = (batteryThreshold) =>
  request.get('/robots/count', {
    params: { batteryThreshold }
  })

// 获取机器人状态分布
export const getRobotStatusDistribution = () => request.get('/robots/status-distribution')
export const getRobotBatteryDistribution = () => request.get('/robots/battery-distribution')

// 获取待机（空闲）机器人列表
export const getIdleRobots = (page = 1, size = 10, name) =>
  request.get('/robots/online', {
    params: { page, size, name }
  })

// 更新机器人状态
export const updateRobotStatus = (id, status) =>
  request.put(`/robots/${id}/status`, null, {
    params: { status }
  })

export const chargeRobot = (id, batteryLevel) =>
  request.put(
    `/robots/charge/${id}`,
    {},
    {
      params: {
        batteryLevel
      }
    }
  )
